layui.use(['layer', 'form', 'admin','laydate', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;
    var laydate = layui.laydate;

    // 让当前iframe弹层高度适应
    admin.iframeAuto();


    //桥梁列表
    var bridgeListAjax =  new $ax(Feng.ctxPath + "/bridge/list", function (data) {
        if(data.success==true){
            $.each(data.data,function(k,v){
                var option = new Option(v.bridgeName,v.bridgeId);
                option.setAttribute("beamNo",v.beamNo);
                $("[name=bridgeId]").append(option);
            })
            form.render("select");
        }
    });
    bridgeListAjax.start();

    //选择桥梁
    form.on('select(getBeamNo)', function(data){
        var beamNo=$(data.elem).find("option:selected").attr("beamNo");
        $("#beamNo").val(beamNo);
    });

    //初始化日志详情数据
    var ajax = new $ax(Feng.ctxPath + "/maintainRecord/view/" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('recordForm',result.data);
    var types = result.data.types;
    if(types){
        $.each(types,function(k,v){
            $(":checkbox[value="+v+"]").prop("checked", true);
        })
    }

    form.render();




    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/maintainRecord/update", function (data) {
            Feng.success("修改成功!");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("修改失败!" + data.responseJSON.message + "!");
        });
        ajax.set(data.field);
        ajax.start();
    });
    // 渲染时间选择框
    laydate.render({
        elem: '#maintainDate',
        trigger: 'click'
    });
});